<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
  <title>登录页面 - 光年(Light Year Admin)后台管理系统模板</title>
  <link rel="icon" href="static/favicon.ico" type="image/ico">
  <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
  <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
  <meta name="author" content="yinqi">
  <link href="../static/css/bootstrap.min.css" rel="stylesheet">
  <link href="../static/css/materialdesignicons.min.css" rel="stylesheet">
  <link href="../static/css/style.min.css" rel="stylesheet">
  <link href="../static/css/animate.css" rel="stylesheet">
  <link href="../static/css/bootstrapValidator.css" rel="stylesheet">
<style>
body {
    display: -webkit-box;
    display: flex;
    -webkit-box-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    align-items: center;
    height: 100%;
  background-image: url("https://qqlykm.cn/bing/bing.php");
  background-size: cover;
}
.login-box {
    display: table;
    table-layout: fixed;
    overflow: hidden;
    max-width: 700px;
}
.login-left {
    display: table-cell;
    position: relative;
    margin-bottom: 0;
    border-width: 0;
    padding: 45px;
}
.login-left .form-group:last-child {
    margin-bottom: 0px;
}
.login-right {
    display: table-cell;
    position: relative;
    margin-bottom: 0;
    border-width: 0;
    padding: 45px;
    width: 50%;
    max-width: 50%;
    background: #67b26f!important;
    background: -moz-linear-gradient(45deg,#67b26f 0,#4ca2cd 100%)!important;
    background: -webkit-linear-gradient(45deg,#67b26f 0,#4ca2cd 100%)!important;
    background: linear-gradient(45deg,#67b26f 0,#4ca2cd 100%)!important;
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#67b26f', endColorstr='#4ca2cd', GradientType=1 )!important;
}
.login-box .has-feedback.feedback-left .form-control {
    padding-left: 38px;
    padding-right: 12px;
}
.login-box .has-feedback.feedback-left .form-control-feedback {
    left: 0;
    right: auto;
    width: 38px;
    height: 38px;
    line-height: 38px;
    z-index: 4;
    color: #dcdcdc;
}
.login-box .has-feedback.feedback-left.row .form-control-feedback {
    left: 15px;
}
@media (max-width: 576px) {
  .login-right {
      display: none;
  }   
}
/*引入必应每日一图*/
</style>
</head>
  
<!--<body style="background-image: url(../static/images/img28.jpg); background-size: cover;">-->
<body>
<div class="modal fade" id="register_frame" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title" id="myModalLabel">
          注册用户
        </h4>
      </div>
      <div class="modal-body">
        <form class="form-horizontal" role="form" id="register_form">
<!--          <input type="hidden" id="id">-->
          <div class="form-group">
            <label for="username_register" class="col-sm-4 control-label">请输入用户名：</label>
            <div class="col-sm-8">
              <input type="text" class="form-control" id="username_register" name="username_register"/>
            </div>
          </div>
          <div class="form-group">
            <label for="realname_register" class="col-sm-4 control-label">请输入姓名：</label>
            <div class="col-sm-8">
              <input type="text" class="form-control" id="realname_register" />
            </div>
          </div>
          <div class="form-group">
            <label for="password_register" class="col-sm-4 control-label">请输入密码：</label>
            <div class="col-sm-8">
              <input type="password" class="form-control" id="password_register" />
            </div>
          </div>
          <div class="form-group">
            <label for="password_register_verify" class="col-sm-4 control-label">请再次输入密码：</label>
            <div class="col-sm-8">
              <input type="password" class="form-control" id="password_register_verify" />
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary" id="register_save_btn">保存</button>
      </div>
    </div>
  </div>
</div>

<div class="bg-translucent p-10">
  <div class="login-box bg-white clearfix">
    <div class="login-left">
      <form>
        <input type="hidden" id="token">
        <div class="form-group has-feedback feedback-left">
          <input type="text" placeholder="请输入您的用户名" class="form-control" name="username" id="username" autocomplete="off"/>
          <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
        </div>
        <div class="form-group has-feedback feedback-left">
          <input type="password" placeholder="请输入密码" class="form-control" id="password" name="password" autocomplete="off"/>
          <span class="mdi mdi-lock form-control-feedback" aria-hidden="true"></span>
        </div>
        <div class="form-group has-feedback feedback-left row">
          <div class="col-xs-7">
            <input type="text" name="verifycode" id="verifycode" class="form-control" placeholder="验证码" autocomplete="off">
            <span class="mdi mdi-check-all form-control-feedback" aria-hidden="true"></span>
          </div>
          <div class="col-xs-5">
            <img src="/ssm/verifyCode/generateCode" class="pull-right" id="captcha" style="cursor: pointer;" onclick="this.src=this.src+'?d='+Math.random();" title="点击刷新" alt="captcha">
          </div>
        </div>
        <div class="form-group">
          <label class="lyear-checkbox checkbox-primary m-t-10">
            <input type="checkbox" id="check5day"><span>5天内自动登录</span>
          </label>
        </div>
        <div class="form-group">
          <button class="btn btn-block btn-primary" type="button" id="login_button">立即登录</button>
        </div>
<!--        <div class="form-group">-->
<!--          <button class="btn btn-block btn-warning" type="button" id="register_button">立即注册</button>-->
<!--        </div>-->
      </form>
    </div>
    <div class="login-right">
<!--      <p><img src="../static/images/logo.png" class="m-b-md m-t-xs" alt="logo"></p>-->
      <p><img src="/ssm/static/images/1629293882_168161.png" class="m-b-md m-t-xs" alt="logo"></p>
      <p class="text-white m-tb-15">Light Year Admin 是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。</p>
      <p class="text-white">Copyright © 2020 <a href="http://lyear.itshubao.com">IT书包</a>. All right reserved</p>
    </div>
  </div>
</div>
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/bootstrap.min.js"></script>
<!--对话框-->
<script src="../static/js/jconfirm/jquery-confirm.min.js"></script>
<script type="text/javascript" src="../static/js/main.min.js"></script>

<!--消息提示-->
<script src="../static/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../static/js/lightyear.js"></script>

<!--表单验证-->
<script src="../static/js/bootstrapValidator.js"></script>
<script type="text/javascript">
$(()=>{
  // getToken();
  loginByToken();


  // $("#register_button").click(()=>{
  //     $("#register_form")[0].reset();
  //     $("#register_frame").modal({
  //       backdrop:"static"
  //     });
  // });
  //
  // $("#register_form").bootstrapValidator({
  //   message: 'This value is not valid',
  //   feedbackIcons: {
  //     valid: 'glyphicon glyphicon-ok',
  //     invalid: 'glyphicon glyphicon-remove',
  //     validating: 'glyphicon glyphicon-refresh'
  //   },
  //   fields: {
  //     username_register:{
  //       message: '用户名验证失败',
  //       validators:{
  //         notEmpty:{
  //           message: "用户名不能为空"
  //         }
  //       }
  //     }
  //   }
  // });
  // $("#register_save_btn").click(()=>{
  //   let username_register = $("#username_register").val();
  //   let realname_register = $("#realname_register").val();
  //   let password_register = $("#password_register").val();
  //   let password_register_verify = $("#password_register_verify").val();
  //   if(password_register === password_register_verify){
  //     // if()
  //     $("#register_form").data("bootstrapValidator").validate();
  //     $.ajax({
  //       type: "POST",
  //       url: "/ssm/user/user",
  //       data: JSON.stringify({
  //         "username" : username_register,
  //         "password" : password_register,
  //         "realName" : realname_register
  //       }),
  //       dataType: "json",
  //       contentType : "application/json",
  //       success:(data)=>{
  //         console.log(data);
  //       }
  //     })
  //   }else{
  //     lightyear.loading('hide');
  //     lightyear.notify('两次输入密码不一致，请核对后再试~', 'warning', 1000);
  //     $("#password_register").val("");
  //     $("#password_register_verify").val("");
      // lightyear.loading('show');
      // 假设ajax提交操作
      // ()=> {
      //
      // }

      // $.alert({
      //   title: '嗨',
      //   content: '这是对用户的简单提示框。 <br> 一些 <strong>HTML</strong> <em>内容</em>',
      //   buttons: {
      //     confirm: {
      //       text: '确认',
      //       btnClass: 'btn-primary',
      //       action: function(){
      //         $.alert('你点击了确认!');
      //       }
      //     },
      //     cancel: {
      //       text: '取消',
      //       action: function () {
      //         $.alert('你点击了取消!');
      //       }
      //     }
      //   }
      // });

  //   }
  // });

  function login(){
    lightyear.loading('show');
    $.ajax({
      type: "POST",
      url: "/ssm/user/login",
      data: {
        username : $("#username").val(),
        password : $("#password").val(),
        verifycode : $("#verifycode").val(),
        // token_login : $("#token").val()
      },
      dataType: "json",
      success:(data)=>{
        console.log(data)
        if(data.code===20000){
          lightyear.loading('hide');
          lightyear.notify('登录成功~', 'success', 10000);
          let check5day = $("#check5day");
          if(data.data.user.role.id===1){
            location.href="/ssm/index/admin/index";
          }else if(data.data.user.role.id===2){
            location.href="/ssm/index/teacher/index";
          }else if(data.data.user.role.id===3){
            location.href="/ssm/index/academic_director/index";
          }
          if(check5day.prop('checked')){
            localStorage.setItem("token",data.data.token);
          }else{
            sessionStorage.setItem("token",data.data.token);
          }

        }else if(data.code===305){
          lightyear.loading('hide');
          lightyear.notify(data.msg+',请重新输入~', 'warning', 1000,'mdi mdi-emoticon-sad');
        }else if(data.code===202){
          lightyear.loading('hide');
          lightyear.notify(data.msg+',请重新输入~', 'warning', 1000,'mdi mdi-emoticon-sad');
        }else if(data.code===203){
          lightyear.loading('hide');
          lightyear.notify(data.msg+',请重新输入~', 'warning', 1000,'mdi mdi-emoticon-sad');
        }else if(data.code===204){
          lightyear.loading('hide');
          lightyear.notify(data.msg+',请联系系统管理员~', 'warning', 1000,'mdi mdi-emoticon-sad');
        }
        else {
          lightyear.loading('hide');
          lightyear.notify(data.msg+',请联系系统管理员~', 'danger', 1000,'mdi mdi-emoticon-sad');
        }
      }
    })
  }

  $("#login_button").click(()=>{
    login();
  });

  $("#login_button").keydown((e)=>{
    if(e.which==13){
      login();
    }
  });

  function loginByToken(){
    let token = localStorage.getItem("token");
    if(token!==''){
      $.ajax({
        type: 'POST',
        url: '/ssm/token/login',
        data: {
          token : token
        },
        dataType: 'json',
        success:(data)=> {
          console.log(data)
          if (data.code === 20000) {
            lightyear.notify('登录成功~', 'success', 10000);
            if (data.data.roleId === '1') {
              location.href = "/ssm/index/admin/index";
            } else if (data.data.roleId === '2') {
              location.href = "/ssm/index/teacher/index";
            } else if (data.data.roleId === '3') {
              location.href = "/ssm/index/academic_director/index";
              //
            }
          }
        }
      })
    }
  }

  // function getToken(){
  //   $.ajax({
  //     type: "GET",
  //     url: "/ssm/token/get-login-token",
  //     dataType: "json",
  //     success : (data)=>{
  //       $("#token").val(data.data.token);
  //     }
  //   })
  // };
})
</script>
</body>
</html>